//
//  YHMachineRateMakeRateCell.m
//  YHApp
//
//  Created by -- on 2021/7/24.
//

#import "YHMachineRateMakeRateCell.h"
#import "YHMachineRateMakeItemCell.h"
#import "HAMachineRateMakeMo.h"

@interface YHMachineRateMakeRateCell ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
/***/
@property (nonatomic, strong) UILabel *titleLabel;

@end

@implementation YHMachineRateMakeRateCell

-(void)setRateModel:(YHMachineRateMakeRatesModel *)rateModel {
    _rateModel = rateModel;
    self.titleLabel.text = _rateModel.label;
    [self.tableView reloadData];

}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _rateModel.item.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 54+28;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YHMachineRateMakeItemCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YHMachineRateMakeItemCellID"];
    if (!cell) {
        cell = [[YHMachineRateMakeItemCell alloc]initWithStyle:0 reuseIdentifier:@"YHMachineRateMakeItemCellID"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.itemModel = _rateModel.item[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

}

-(void)layoutSubviews {
    [super layoutSubviews];
    
    self.contentView.backgroundColor = [UIColor khaBGColor];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.height.mas_offset(20);
        make.top.mas_equalTo(17);
    }];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(54);
        make.bottom.mas_equalTo(0);
    }];
}

- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [UILabel ha_NLabelWithFont:18 textColor:@"#858B9C" text:@"" alignment:0];
        [self.contentView addSubview:_titleLabel];
    }
    return _titleLabel;
}

- (UITableView *)tableView {
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero];
        // 去掉滚动条
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.contentView addSubview:_tableView];
    }
    return _tableView;
}

@end
